package com.jiji.miaosha.mapper;

import com.jiji.miaosha.entity.Item;
import com.jiji.miaosha.mapper.provide.ItemMapperProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ItemMapper {

    @Select("select * from item where id=#{itemId}")
    Item queryItemById(@Param("itemId") Integer id);


    @InsertProvider(type = ItemMapperProvider.class,method = "insertSelective")
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "item.id")
    int insertSelective(@Param("item") Item item);

    @Select("select * from item order by sales desc")
    List<Item> listItem();

    @Update("update item set sales=sales+#{sales} where id=#{itemId}")
    int increaseSales(@Param("itemId") Integer itemId,@Param("sales") Integer sales);
}
